home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_130 / qman / msmooth.asm < prev    next >
Assembly Source File  |  1992-05-06  |  6KB  |  149 lines

  1. ****************************************************************************
  2. *
  3. *         Draws a Row of Pixels in Mandelbrot Set (with smoothing)
  4. *
  5. *         C must set the following variables prior to call:
  6. *                xptr   :  pointer to table of x-values 
  7. *                imagc  :  imaginary part of current pixel row
  8. *                bp1-4  :  pointers to the four bit planes
  9. *  
  10. *         Integers are 2**26 times the actual values in the complex plane
  11. *
  12. ****************************************************************************
  13.  
  14. *  First some macros we will need.....
  15.  
  16. EvalPix     MACRO
  17.             moveq       #79,d3               set counter to 79
  18.             clr.l       d0                   zero out real_z
  19.             clr.l       d2                   zero out imag_z
  20.  
  21. repeat\1    moveq       #13,d7               number of bits to shift
  22.             asr.l       d7,d0                divide real_z by 2**13
  23.             asr.l       d7,d2                divide imag_z by 2**13
  24.  
  25.             move.l      d0,d1                real_z
  26.             sub.w       d2,d0                real_z - imag_z
  27.             add.w       d1,d1                2 * real_z
  28.             muls        d1,d2                2 * real_z * imag_z
  29.             sub.w       d0,d1                real_z + imag_z
  30.             muls        d1,d0                real_z**2 - imag_z**2
  31.            
  32.             add.l       d5,d0                add real_c to get new real_z
  33.             move.l      d0,d7                create temp copy of real_z
  34.             bpl         pos_1\1              if real_z positive, do nothing
  35.             neg.l       d7                   take absolute value of real_z
  36. pos_1\1     add.l       d6,d2                add imag_c to get new imag_z
  37.             move.l      d2,d1                load working copy of imag_z
  38.             bpl         pos_2\1              if imag_z positive, do nothing
  39.             neg.l       d1                   take absolute value of imag_z
  40. pos_2\1     add.l       d1,d7                d7 contains the norm of z
  41.             subq        #1,d3                decrement counter by 1
  42.             beq         pixout\1             if 79 iters, draw the pixel
  43.             subi.l      #200000000,d7        reduce the norm by 200 million 
  44.             bmi         repeat\1             if z not exploding, continue
  45.             addq        #1,d3                increment counter by 1
  46.             asr.l       #3,d3                color is 1/8 number of iters
  47.             addq        #3,d3                range 3 to 12
  48. pixout\1    nop
  49.             ENDM
  50.  
  51. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  52.  
  53. WritePix    MACRO
  54.             tst.l       d4                   examine bit within byte
  55.             bne         plane1\1             if not bit zero, poke planes
  56.             moveq       #8,d4                reset to bit 8 (next will be 7)
  57.             lea         1(a0),a0             incr addr within 1st bit plane
  58.             lea         1(a1),a1                              2nd
  59.             lea         1(a2),a2                              3rd
  60.             lea         1(a3),a3                              4th
  61. plane1\1    subq.l      #1,d4                decrement bit within byte by 1
  62.  
  63. nomenus\1   btst        d4,(a0)              if we've hit a menu-- STOP!
  64.             bne         nomenus\1 
  65.             btst        d4,(a1)
  66.             bne         nomenus\1
  67.             btst        d4,(a2)
  68.             bne         nomenus\1
  69.             btst        d4,(a3)
  70.             bne         nomenus\1
  71.  
  72.             btst        #0,d3                examine 1st bit of color
  73.             beq         plane2\1             if bit off, leave screen alone
  74.             bset        d4,(a0)              turn current bit on in plane
  75. plane2\1    btst        #1,d3              
  76.             beq         plane3\1
  77.             bset        d4,(a1)
  78. plane3\1    btst        #2,d3
  79.             beq         plane4\1
  80.             bset        d4,(a2)
  81. plane4\1    btst        #3,d3
  82.             beq         writeout\1
  83.             bset        d4,(a3)
  84. writeout\1  nop
  85.             ENDM
  86.  
  87. *------------------------------------------*
  88. *           The main routine!              *
  89. *------------------------------------------*
  90.  
  91.             XDEF        _msmooth             This tells C about us
  92.             SECTION     text,code
  93.  
  94. _msmooth    movem.l     d2-d7/a2-a6,-(a7)    save registers
  95. setup       moveq       #8,d4                bit within screen byte
  96.             move.l      #638,pixct           pixel counter for current row
  97.             move.l      _xptr,a5              
  98.             move.l      _imagc,d6
  99.             move.l      _bp1,a0              
  100.             move.l      _bp2,a1
  101.             move.l      _bp3,a2
  102.             move.l      _bp4,a3
  103.   
  104. xloop       move.l      (a5),d5              move next x-value into D5
  105.  
  106.             EvalPix     0                    the i-th pixel
  107.             move.l      d3,lastval 
  108.             WritePix    0
  109.  
  110.             adda        #8,a5
  111.             move.l      (a5),d5
  112.             EvalPix     2                    the (i+2)nd pixel
  113.             move.l      d3,nextval
  114.             suba        #4,a5
  115.             
  116.             cmp         lastval,d3
  117.             beq         nextpix
  118.             
  119.             move.l      (a5),d5
  120.             EvalPix     1                    the (i+1)st pixel
  121.  
  122. nextpix     WritePix    1                         
  123.             move.l      nextval,d3
  124.             WritePix    2
  125.  
  126.             adda        #8,a5
  127.  
  128. next_x      subi.l      #3,pixct             decrement x counter
  129.             bpl         xloop                if not done with row, continue
  130.  
  131.             add.l       #80,_bp1             advance to next display line
  132.             add.l       #80,_bp2
  133.             add.l       #80,_bp3
  134.             add.l       #80,_bp4
  135.  
  136.             movem.l     (a7)+,d2-d7/a2-a6    restore registers
  137.           
  138.             rts
  139.  
  140.             SECTION     udata,bss      
  141.             XREF        _xptr,_imagc
  142.             XREF        _bp1,_bp2,_bp3,_bp4
  143. pixct       DS.L        1
  144. lastval     DS.L        1
  145. nextval     DS.L        1
  146.             END
  147.  
  148.